package server;

import dataContracts.CommandParser;
import dataContracts.CommandType;

class EqualityHandler implements Runnable {
	ClientConnection client;
	ServerProgram server;
	String commandText;
	
	EqualityHandler(ClientConnection client, ServerProgram server, String commandText) {
		this.server = server;
		this.client = client;
		this.commandText = commandText;
	}
	
	@Override
	public void run() {
		//TODO: how to avoid reloading the directory contents each time?
		server.directory.loadFiles();
		
		String checksumProvided = CommandParser.getCommandText(CommandType.IsEqual, commandText),
				serverChecksum = server.directory.getChecksum();
		
		String response = CommandParser.buildCommand(CommandType.IsEqual, (checksumProvided.equalsIgnoreCase(serverChecksum)) ? "1" : "0");
		client.command(response);
	}
}